package com.tmt.im.jpa.entity;

import com.tmt.data.jpa.entity.TmtBaseEntity;
import com.tmt.im.common.enums.RedPackageType;
import com.tmt.im.jpa.converter.StringAndLongListConverter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import java.io.Serial;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

/**
 * @Description TODO
 * @Author wuyi
 * @Date 2024/9/2 11:33
 * @Version 1.0
 **/
@Getter
@Setter
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "red_package")
@Tag(name = "RedPackage", description = "红包实体对象")
public class RedPackage extends TmtBaseEntity {

    @Serial
    private static final long serialVersionUID = -4959820406285260761L;

    @Schema(name = "title", description = "红包表面的文字内容")
    @Column(nullable = false)
    private String title;

    @Schema(name = "skinId", description = "红包使用的皮肤编号")
    private Long skinId;

    @Schema(name = "type", description = "红包类型")
    @Column(nullable = false)
    @Enumerated(EnumType.STRING)
    private RedPackageType type;

    @Schema(name = "amount", description = "红包总额度，单位：分")
    @Column(nullable = false)
    private Long amount;

    @Schema(name = "splitCount", description = "红包分成多少份. LUCKY类型的红包需要指定, 其他类型的红包,本字段值等于receiverIds列表项的数量")
    @Column(nullable = false)
    private int splitCount;

    @Schema(description = "是否已经领取完毕")
    @Column(nullable = false)
    private boolean receivedAlready = false;

    @Convert(converter = StringAndLongListConverter.class)
    @Schema(name = "receiverIds", description = "接收红包的用户ID列表, LUCKY类型的红包本字段为null")
    @Column(name = "receiver_ids")
    private List<Long> receiverIds;

    @ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "creator_id")
    @Schema(name = "creator", description = "红包创建人")
    private IMUser creator;

    @ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
    @JoinColumn(name = "session_id")
    @Schema(description = "群组ID")
    private ChatSession session;

}
